package com.zmn.oms.common.utils;

import com.zmn.common.utils.date.DateUtil;

import java.util.Date;
import java.util.Objects;

/**
 * 类描述：时间转换可视化文本显示
 *
 * @author yule
 * @date 2020/8/25 18:47
 */
public class TimeTextUtil {

    public static String getDutyText(String dutyTime) {
        Date duty = DateUtil.parse(dutyTime);
        return getDutyText(duty);
    }

    public static String getDutyText(Date dutyTime) {
        if (dutyTime == null) {
            return "";
        }
        // 预约时间str
        String dutyTimeStr = DateUtil.toString(dutyTime, DateUtil.FORMAT_DATE);
        // 今天
        String today = DateUtil.getNowFormatted(DateUtil.FORMAT_DATE);
        // 昨天
        String yesterday = DateUtil.toString(DateUtil.getNowDefer(-1), DateUtil.FORMAT_DATE);
        // 明天
        String tomorrow = DateUtil.toString(DateUtil.getNowDefer(1), DateUtil.FORMAT_DATE);
        // 后天
        String afterTomorrow = DateUtil.toString(DateUtil.getNowDefer(2), DateUtil.FORMAT_DATE);
        // 当前时间在第几周
        int nowWeek = DateUtil.getNowPoint(DateUtil.UNIT_WEEK);
        // 预约时间在第几周
        int dutyWeek = DateUtil.getDatePoint(dutyTime, DateUtil.UNIT_WEEK);

        if (Objects.equals(today, dutyTimeStr)) {
            return "今天";
        } else if (Objects.equals(yesterday, dutyTimeStr)) {
            return "昨天";
        } else if (Objects.equals(tomorrow, dutyTimeStr)) {
            return "明天";
        } else if (Objects.equals(afterTomorrow, dutyTimeStr)) {
            return "后天";
        } else if (Objects.equals(nowWeek, dutyWeek)) {
            String week = DateUtil.getWeekOfDate(dutyTime);
            Date nowBefore = DateUtil.getNowDefer(-1);
            if (nowBefore.before(dutyTime)) {
                return "本" + week;
            } else {
                return "";
            }
        } else if (dutyWeek - nowWeek == 1) {
            String week = DateUtil.getWeekOfDate(dutyTime);
            return "下" + week;
        } else {
            return "";
        }
    }

}

